qui(
    function (require, exports, module) {
        WrapSys.Dao = $.extend({}, EpgWeb.Dao, {
            cache: {},
            settings: {
                index: 1,
                newsSubmitIndex: 1,
                newsDelIndex: 1,
                stime: 0,
                etime: 0,
                pic: 0,
                taskid: 0,
                lastImg: 0,
                delList: [],
                subData: [],
                isStart: false,
                isSetFpTime: false,
                lb: 1,
                firstFpTime: 0,
                last_i: 0,   // 上次识的库索引
                adLibList: [],
                isOver: 1,  //防止并发
                fpTime: 'fp_time',
                // page use
                startQuery: "",
                period: '',
                linePicNum: 9,
                today: '',
                g_ocrList: [],
                g_acrList: [],
                reg_last_id: 0
            },
            playOneInfo: {mouseenter: false},
            getParamsData: function () {
                return this.getDataByName("params");
            },
            getDotData: function () {
                return this.getDataByName("dot");
            },
            getDataByName: function (targetName) {
                if (!this.cache.hasOwnProperty(targetName)) {
                    if (this.hasOwnProperty("method_" + targetName)) {
                        var target = this["method_" + targetName]();
                        this.cache[targetName] = target;
                        return target;
                    } else {
                        return null;
                    }
                } else {
                    return this.cache[targetName];
                }
            },
            method_params: function () {
                var queryStringObj = WrapSys.Util.getUrlParams();
                var obj = {};
                obj["channel_name"] = queryStringObj['channel_code'];
                obj["ip"] = queryStringObj['ip'];
                obj["freeType"] = queryStringObj['free_type'];
                obj["_channel_id"] = queryStringObj['channel_id'];
                obj["_channel_name_str"] = queryStringObj['cn'];
                obj["locationCategory"] = queryStringObj['locationCategory'];
                obj["location"] = queryStringObj['location'];
                obj["startTime"] = queryStringObj['startTime'];
                obj["endTime"] = queryStringObj['endTime'];
                WrapSys.Config.MASK_TEST = queryStringObj['MASK_TEST'] || null;
                return obj;
            },
            method_dot: function () {
                var params = this.getParamsData();
                var obj = {};
                //   obj.dotUrl = 'http://' + params.ip + ':8080/dot/dodot';
                obj.adUrl = 'http://' + params.ip + ':8080/dot/doadstore'; // 广告入库学习
                obj.listUrl = 'http://' + params.ip + ':8080/dot/json';
                obj.initUrl = 'http://' + params.ip + ':8080/dot/init';
                // obj.cateUrl = 'http://' + params.ip + ':8080/dot/cate';
                obj.sty2Url = 'http://' + params.ip + ':8080/dot/sty2';//智能分析
                obj.ocrUrl = 'http://' + params.ip + ':8080/dot/ocr';
                obj.acrUrl = 'http://' + params.ip + ':8080/dot/acr';
                obj.channelInfoUrl = 'http://' + params.ip + ':8080/channel/channelinfo';
                obj.analysis = 'http://' + params.ip + ':9090/dot/analysis';
                obj.sty = 'http://' + params.ip + ':8080/dot/sty'; // 自动拆条
                obj.codeVersionUrl = 'http://' + params.ip + ':8080/version'; // 编码器版本号
                obj.smartLibrary = 'http://' + params.ip + ':8080/dot/';

                // http://10.23.70.35:8080/dot/ocrimage?key=33839&image_id=18&channel_id=233&from_client=true
                obj.ocrimage = 'http://' + params.ip + ':8080/dot/ocrimage'; // 获取生成原始码流图片接口
                obj.findImage = 'http://' + params.ip + ':8080/dot/findocrimage';// 获取图片接口
                //         obj.ocrimage = 'http://' + params.ip + ':8080/dot/ocrimage22'; // 获取生成原始码流图片接口
                //http://10.23.70.35:8080/dot/ocrposition?key=33839&image_id=18&channel_id=233&x=1&y=2&w=255&h=400&from_client=true
                obj.ocrposition = 'http://' + params.ip + ':8080/dot/ocrposition';// 前端截图后将坐标传给服务器接口
                obj.ocrresult1 = 'http://' + params.ip + ':8080/dot/ocrresult1';// 前端截图后将坐标传给服务器接口
                obj.ocrresult2 = 'http://' + params.ip + ':8080/dot/ocrresult2';// 前端截图后将坐标传给服务器接口
                //    obj.ocrresult1 = 'http://' + params.ip + ':8080/dot/ocrresult122';// 前端截图后将坐标传给服务器接口
                //        obj.appendUrl = 'http://' + params.ip + ':8080/dot/append';// 分片追加接口

                // /dot/delogoimage?image_id=XX&channel_code=xx&from_client=true&key=xx&delogo=xx
                obj.delogoimage = 'http://' + params.ip + ':8080/dot/delogoimage'// 遮标预览
                obj.autoTitleUrl = 'http://' + params.ip + ':8080/dot/autoTitle'// 获取自动识别标题

                obj.wrapSubmit = 'http://' + params.ip + ':8080/dot/append2'// 包装提交
                obj.wrapReset = 'http://' + params.ip + ':8080/dot/reset'// 包装任务重置
                obj.wrapPublish = 'http://' + params.ip + ':8080/dot/publish'// publish
                return obj;
            },
            // 获取合作方信息
            getCooperativePartner: function (options, callback) {
                if (options.channeltype == 'undefined' || options.channelalias == 'undefined' || options.channeltype == '' || options.channelalias == '')
                    return '';
                $.get(WrapSys.urlConfig.partnerUrl, options, function (res) {
                    if (res.code == 200) {
                        callback.call(this, res.response.data);
                    } else {
                        console.log("【合作方失败信息】" + res.msg);
                    }
                }, 'json');
            },
            getCodeVersion: function (options) {
                var codeVersionUrl = this.getDotData().codeVersionUrl;
                $.ajax({
                    cache: false,
                    async: false,
                    type: "get",
                    url: codeVersionUrl,
                    data: {
                        'data': JSON.stringify(options)
                    },
                    success: function (data) {
                        WrapSys.Dao.storageData('coderVersion', data);
                    },
                    error: function () {
                        console.log('请求编码器版本号失败,请稍后再试！');
                    }
                });
            },
            getChannelType: function (handler) {
                var options = {
                    url: WrapSys.Constant.thirdUrl_channel,
                    type: "get",
                    data: {size: 100},
                    success: function (data) {
                        var formatData = [];
                        $.each(data.data, function (i, element) {
                            formatData.push({id: element.id, label: element.name, value: element.name})
                        })
                        handler(formatData);
                        console.log("renderPanel happen");
                    },
                    error: function (data) {
                        console.log("error happen");
                    }
                }
                this.sendProxy(options);
            },
            delNews: function (data, callback) {
                var url = this.getDotData().sty;
                var options = {
                    type: "post",
                    url: url,
                    dataType: "json",
                    data: data,
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                }
                $.ajax(options);
            },
            getNewsList: function (data, callback) {
                var url = this.getDotData().sty;
                this.doGet(url, data, callback);
            },
            getOcrImage: function (data, callback) {
                var url = this.getDotData().ocrimage;
                this.doGet(url, data, callback);
            },
            doFindImage: function (timeKey, data, callback) {
                var self = this;
                var url = this.getDotData().findImage;
                if (self.cache[timeKey] != null) {
                    clearInterval(this.cache[timeKey].timeId);
                    self.cache[timeKey] = null;
                }
                var tempData = {
                    timeId: 0,
                    restTry: 5
                }
                self.cache[timeKey] = tempData;
                self.cache[timeKey].timeId = setInterval(function () {
                    console.log("开始加载" + timeKey);
                    self.doGet(url, data, function (sdata) {
                        if (sdata.code == "A00000") {
                            console.log("完成加载" + timeKey);
                            clearInterval(self.cache[timeKey].timeId);
                            self.cache[timeKey] = null;
                            callback(sdata);
                        } else {
                            self.cache[timeKey].restTry--;
                            if (self.cache[timeKey].restTry <= 0) {
                                clearInterval(self.cache[timeKey].timeId);
                                self.cache[timeKey] = null;
                                console.log("加载失败"+ timeKey);
                            }
                        }
                    });
                }, 1000)
            },
            getOcrResult: function (data, callback) {
                var url = this.getDotData().ocrresult1;
                this.doGet(url, data, callback);
            },
            getOcrResult2: function (data, callback) {
                var url = this.getDotData().ocrresult2;
                this.doGet(url, data, callback);
            },
            getMaskResult: function (data, callback) {
                var url = this.getDotData().delogoimage;
                this.doGet(url, data, callback);
            },

            postOcr2Data: function (data, callback) {
                var options = {
                    type: "post",
                    url: WrapSys.urlConfig.submitOcr2DataUrl,
                    dataType: "json",
                    data: data,
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                }
                $.ajax(options, "");
            },
            // original structure
            storageData: function (name, value) {
                var DSN = $('#storage-data');
                if (!value && !name)
                    return '';
                else if (value == undefined)
                    return DSN.data(name);
                else
                    DSN.data(name, value);
            },
            getInitTaskId: function (data, callback) {
                var url = this.getDotData().initUrl;
                this.doGet(url, data, callback);
            },
            submitLogEntity: function (data, callback) {
                var url = WrapSys.urlConfig.submitLogUrl;
                var options = {
                    type: "post",
                    url: url,
                    dataType: "json",
                    data: {data: JSON.stringify(data)},
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                }
                Ancestor.Dao.ajax(options, "/vod/saveLog");
            },
            submitEpisodeLogEntity: function (data, callback) {
                var url = WrapSys.urlConfig.submitEpisodeLogUrl;
                var options = {
                    type: "post",
                    url: url,
                    dataType: "json",
                    data: {data: JSON.stringify(data)},
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                }
                Ancestor.Dao.ajax(options, "/vod/saveEpisodeLog");
            },
            postSync: function (postUrl, postData, handler, sync) {
                var async = sync == null ? true : sync != true;
                var options = {
                    cache: false,
                    async: async,
                    type: "post",
                    dataType: "json",
                    url: postUrl,
                    data: postData,
                    success: function (res) {
                        handler.doSuc(res);
                    },
                    error: function () {
                        handler.doError();
                    }
                }
                Ancestor.Dao.ajax(options);
            },
            dopeditorSubmit: function (sendData, handler) {
                var ajaxTimeoutTest = $.ajax({
                    cache: false,
                    async: false,
                    type: "post",
                    url: WrapSys.urlConfig.redirect,
                    timeout: 10000,
                    dataType: "json",
                    data: sendData,
                    success: function (res) {
                        handler.doSuc(res);
                    },
                    error: function (XMLHttpRequest, status) {
                        handler.doError(XMLHttpRequest, status);
                    }
                })
            },
            getAutoTitleList: function (sendData, handler) {
                var url = this.getDotData().autoTitleUrl;
                this.doGet(url, sendData, handler);
                //   handler({code: VODNew.Config.CODE_SUC, title: JSON.stringify(["测试e标题1", "测试标题s12", "测题13","测试标题13","测试标题23","测试标题33","测试标题43","测试标题63"]) });
                //   handler({code: VODNew.Config.CODE_SUC, data: []})
            },
            transElement: function (element) {
                var materialElement = {id: element.id, name: element.name, source: element, time: ""};
                switch (element.type) {
                    case 0:
                        materialElement.type = "视频";
                        materialElement.url = element.picAddress;
                        materialElement.time = parseInt( element.duration);
                        break;
                    case 1:
                        materialElement.type = "图片";
                        materialElement.url = element.picAddress;
                        break;
                }
                if (element.contentType == null) {
                    element.contentType = 0;
                }
                materialElement.contentType = WrapSys.Config.MATERIAL_CONTENT_TYPE["key" + element.contentType];
                if (materialElement.contentType == null) {
                    materialElement.contentType = "无";
                }
                return materialElement
            },
            makeWrapHandler: function (handler) {
                var mock = false;
                var self = this;
                var wrapHandler = function (rdata) {
                    if (handler != null) {
                        if (rdata != null && rdata.code == WrapSys.Config.CODE_SUC) {
                            var imageId = parseInt($(".red").parent().find(".pid").html());
                            var mockUrl = $("#img-" + imageId).attr("src");
                            if (mock) {
                                rdata.data.result = [
                                    { id: 1, name: "test1", url: mockUrl, time: "01:30", type: "视频", contentType: "无"  },
                                    { id: 2, name: "test2", url: mockUrl, time: "01:30", type: "图片", contentType: "无" }
                                ]
                            } else {
                                var transArr = [];
                                $.each(rdata.data.result, function (i, element) {
                                    transArr.push(self.transElement(element))
                                })
                                rdata.data.result = transArr;
                            }
                        }
                        handler(rdata);
                    }
                }
                return wrapHandler
            },

            getMaterialList: function (sendData, handler) {
                var url = WrapSys.urlConfig.getMaterialUrl;
                if (WrapSys.Config.REMOTE_ROUTE) {
                    url = "http://10.23.85.152:8500/vod/ad/getList";
                }
                handler = this.makeWrapHandler(handler)
                var options = {
                    type: "post",
                    url: url,
                    dataType: "json",
                    data: {paramsObj: JSON.stringify(sendData) ,pageSize:10,pageNo:1},
                    success: function (data) {
                        handler.call(this, data);
                    },
                    error: function (data) {
                        handler.call(this, data);
                    }
                }
                if (WrapSys.Config.REMOTE_ROUTE) {
                    this.sendProxy(options, {Sign: "#f93Uc31K24()_@"})
                } else {
                    Ancestor.Dao.ajax(options, "/vod/ad/getList");
                }
            },
            doAdvertTest: function (handler) {
                var params = this.getDotData();
                this.sendAjax(params.doadadd, "post", {from_client: true}, handler)
            },
            doWrapReset: function (programId, handler) {
                var params = this.getDotData();
                this.sendAjax(params.wrapReset, "post", {from_client: true, programId: programId}, handler)
            },
            doWrapPublish:function(programId,handler){
                var params = this.getDotData();
                this.sendAjax(params.wrapPublish, "post", {from_client: true, programId: programId}, handler)
            }

        })
    }
);